package org.si.graphics;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;

/**
 * Provides an instance of a LinearGradientPaint that will fill the specified dimensions in the target area.
 */
public class LinearGradientPaintProvider extends MultipleGradientPaintProvider {

    private final float x1;
    private final float y1;
    private final float x2;
    private final float y2;





    public LinearGradientPaintProvider(float x1, float y1, float x2, float y2,
                                       float[] fractions, Color[] colors) {
        this(x1, y1, x2, y2, fractions, colors, MultipleGradientPaint.CycleMethod.NO_CYCLE,
                MultipleGradientPaint.ColorSpaceType.SRGB, new AffineTransform());
    }





    public LinearGradientPaintProvider(float x1, float y1, float x2, float y2,
                                       float[] fractions, Color[] colors,
                                       MultipleGradientPaint.CycleMethod cycleMethod) {
        this(x1, y1, x2, y2, fractions, colors, cycleMethod, MultipleGradientPaint.ColorSpaceType.SRGB,
                new AffineTransform());
    }





    public LinearGradientPaintProvider(float x1, float y1, float x2, float y2,
                                       float[] fractions, Color[] colors,
                                       MultipleGradientPaint.CycleMethod cycleMethod,
                                       MultipleGradientPaint.ColorSpaceType colorSpace,
                                       AffineTransform gradientTransform) {
        super(fractions, colors, cycleMethod, colorSpace, gradientTransform);
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }





    @Override
    public Paint get(Component c, int x, int y, int width, int height) {
        return new LinearGradientPaint(
                new Point2D.Float(x + x1 * width, y + y1 * width),
                new Point2D.Float(x + x2 * width, y + y2 * width),
                fractions, colors, cycleMethod, colorSpace, gradientTransform);
    }
}
